<?php

  use kartik\select2\Select2;
  use yii\web\JsExpression;
  use yii\helpers\Html;
  use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\News */
/* @var $form yii\widgets\ActiveForm */
?>


    <?php $form = ActiveForm::begin([
            'fieldConfig' => [
                'template' => "{label}\n<div class=\"col-sm-10  col-sm-6\">{input}<label class='error'>{error}</label></div>",
                'labelOptions' => ['class' => 'col-sm-2 bx_label'],
            ],
        ]); ?>
<div class="ibox-content">
    <?php
      //$form->field($model, 'catid')->textInput()


      // The controller action that will render the list
      $url = \yii\helpers\Url::to(['ajax']);

      // The widget



      // Get the initial city description
      $cityDesc = empty($model->cat) ? '' : $model->cat->title;

      echo $form->field($model, 'catid')->widget(Select2::classname(), [
        'initValueText' => $cityDesc, // set the initial display text
        'options' => ['placeholder' => 'Search for a catid ...'],
        'pluginOptions' => [
          'allowClear' => true,
          'minimumInputLength' => 2,
          'language' => [
            'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
          ],
          'ajax' => [
            'url' => $url,
            'dataType' => 'json',
            'data' => new JsExpression('function(params) { return {q:params.term}; }')
          ],
          'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
          'templateResult' => new JsExpression('function(rs) { return rs.text; }'),
          'templateSelection' => new JsExpression('function (rs) { return rs.text; }'),
        ],
      ]);



    ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

  <?= $form->field($model, 'image')->widget('\jjbx\kindeditor\KindEditor',
    [
      'clientOptions'=>[
        'allowFileManager'=>'true',
        'allowUpload'=>'true'
      ],
      'editorType'=>'image-dialog',
      'toId'=>'news-content',
    ]);
  ?>

    <?= $form->field($model, 'keywords')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>

  <?= $form->field($model, 'content')->widget('jjbx\kindeditor\KindEditor',
    ['clientOptions'=>['allowFileManager'=>'true',
      'allowUpload'=>'true']])
  ?>

    <?= $form->field($model, 'listorder')->textInput() ?>


    <?= $form->field($model, 'source')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'click_num')->textInput() ?>

    <div class="form-group">
        <div class="col-sm-8  col-sm-offset-2">
            <?= Html::submitButton($model->isNewRecord ? '提交' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>
    </div>
</div>
    <?php ActiveForm::end(); ?>

